/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.web.portlet.bean.impl;

import java.io.UnsupportedEncodingException;

import com.genia.toolbox.basics.exception.technical.TechnicalEncodingException;
import com.genia.toolbox.web.portlet.bean.PortletView;

/**
 * Implementation of the interface used to provide sub-portlets to the portlets
 * containers.
 */
public class PortletViewImpl
    implements PortletView
{

  /**
   * the content of the portlet.
   */
  public byte[] bytes;

  /**
   * the encoding of the portlet.
   */
  public String characterEncoding;

  /**
   * the identifier of the portlet.
   */
  public String identifier;

  /**
   * the content of the portlet as a <code>String</code>.
   */
  private transient String text = null;



  /**
   * getter for the content of the portlet as a <code>String</code>.
   * 
   * @return the content of the portlet as a <code>String</code>
   * @throws TechnicalEncodingException
   *           if the encoding does not exist or the bytes cannot represent a
   *           string in this encoding
   */
  public String getText()
      throws TechnicalEncodingException
  {
    if (text == null) {
      try {
        text = new String(getBytes(), getCharacterEncoding());
      }
      catch (final UnsupportedEncodingException e) {
        throw new TechnicalEncodingException(e);
      }
    }
    return text;
  }



  /**
   * getter for the bytes property.
   * 
   * @return the bytes
   */
  public byte[] getBytes()
  {
    return bytes;
  }



  /**
   * setter for the bytes property.
   * 
   * @param bytes
   *          the bytes to set
   */
  public void setBytes(final byte[] bytes)
  {
    this.bytes = bytes;
  }



  /**
   * getter for the characterEncoding property.
   * 
   * @return the characterEncoding
   */
  public String getCharacterEncoding()
  {
    return characterEncoding;
  }



  /**
   * setter for the characterEncoding property.
   * 
   * @param characterEncoding
   *          the characterEncoding to set
   */
  public void setCharacterEncoding(final String characterEncoding)
  {
    this.characterEncoding = characterEncoding;
  }



  /**
   * getter for the identifier property.
   * 
   * @return the identifier
   */
  public String getIdentifier()
  {
    return identifier;
  }



  /**
   * setter for the identifier property.
   * 
   * @param identifier
   *          the identifier to set
   */
  public void setIdentifier(final String identifier)
  {
    this.identifier = identifier;
  }

}
